package steps
{
	import laya.display.Sprite;
	import laya.events.Event;
	import laya.maths.Point;
	import laya.maths.Rectangle;
	
	import ui.steps.Dia_BiaozhunxianUI;
	
	public class BiaoZhunxian extends Dia_BiaozhunxianUI
	{
		private var drawbg:Sprite=new Sprite();
		private var drawbg2:Sprite=new Sprite();
		private var isDown:Boolean=false;
		private var lastPoint:Point;
		private var lineType:String="row";
		//		private var lineType:String="col";
		private static var _ins:BiaoZhunxian;
		//y=kx+b
		
		//x=(y-b)/k
		public static const k:Number=1/0.743;
		public static const b:Number=-0.00942;
		public function BiaoZhunxian()
		{
			super();
			size(1615,1060);
		}
		override public function onAwake():void{
			this.bg.addChild(drawbg);
			this.bg.addChild(drawbg2);
			drawbg2.alpha=0.8;
			btn.on(Event.CLICK,this,function():void{});
			btn_od.on(Event.MOUSE_DOWN,this,mouseDown);
			btn_od.on(Event.MOUSE_UP,this,mouseUp);
			btn_od.on(Event.MOUSE_OUT,this,mouseUp);
			btn_od.on(Event.MOUSE_MOVE,this,mouseMove);
		}
		public static function getInstance():BiaoZhunxian{
			if(_ins==null){
				_ins=new BiaoZhunxian();
			}
			return _ins;
		}
		private function mouseMove():void
		{
			// TODO Auto Generated method stub
			if(isDown){
				txt_od.text=Math.round((1-btn_od.y/bg.height)*1000)/1000+"";
				txt_od.y=btn_od.y;
				txt_value.text=Math.round((Number(txt_od.text)-b)/k*1000)/1000+"";
				txt_value.x=Number(txt_value.text)*bg.width/0.8;
				drawbg.graphics.clear();
				drawbg.graphics.drawLine(txt_value.x,bg.height,txt_value.x,btn_od.y,"#0758fc",2);
				drawbg2.graphics.clear();
				drawbg2.graphics.drawLine(0,btn_od.y,txt_value.x,btn_od.y,"#ff0000",2);
			}
		}
		
		private function mouseUp():void
		{
			// TODO Auto Generated method stub
			if(isDown){
				isDown=false;
				lineType="";
				btn_od.stopDrag();
			}
		}
		
		private function mouseDown():void
		{
			// TODO Auto Generated method stub
			isDown=true;
			drawbg.graphics.clear();
			drawbg2.graphics.clear();
			btn_od.startDrag(new Rectangle(-3,0,-3,707));
			txt_od.text=Math.round((1-btn_od.y/bg.height)*1000)/1000+"";
			txt_od.y=btn_od.y;
			txt_value.text=Math.round((Number(txt_od.text)-b)/k*1000)/1000+"";
			txt_value.x=Number(txt_value.text)/0.8*bg.width;
		}
	}
}